# encoding: utf-8
"""
!/usr/bin/python3
@Author: Gao Shuo
@Time: 2018/9/11 20:53 
@ReadMe:
    Input: 
    Output:
    提取图片中有某标签的
"""

from PIL import Image
import os.path
import pandas as pd
import sys

def examine_color(im,width, height, color_need ):
    color_in = False
    for i in range(width):
        for j in range(height):
            color = im.getpixel(xy=(i, j))
            if color in color_need:
                color_in = True
                return True
    if not color_in :
        return False



if __name__ == "__main__":
    path = sys.argv[1]
    dest = sys.argv[2]
    width = int(sys.argv[3])
    height = int(sys.argv[4])
    color_need = sys.argv[4].split(",")
    color_need = [int(x) for x in color_need]

    li = os.listdir(path)
    pic_select = []
    for filepath in li:
        filein = os.path.join(path, filepath)
        im = Image.open(filein)
        if examine_color(im, width, height, color_need):
            pic_select.append(im)











